package edu.towson.cis.cosc490.oimani1.lab3;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ToDoListActivity extends Activity implements OnClickListener, OnLongClickListener{
	
	public Button m_addButton;
	EditText m_editText;
	LinearLayout m_itemListView;
	EditText ToDoItem;
	int turn=0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_to_do_list);
        initLayout();
        m_addButton.setOnClickListener(this);
    }

    private void initLayout() {
	 m_addButton = (Button) this.findViewById(R.id.button1);
	 //m_editText = (EditText) this.findViewById(R.id.editText1);	
	 m_itemListView = (LinearLayout) this.findViewById(R.id.toDoListView);
	}

	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_to_do_list, menu);
        return true;
    }
	
	public void onClick(View v){
    	String toDoItem = m_editText.getText().toString();
    	TextView newItemTextView = new TextView(this);
    	newItemTextView.setText(toDoItem);
    	newItemTextView.setOnLongClickListener(this);
    	m_itemListView.addView(newItemTextView);
    	m_editText.setText("");
    	if(turn==0){
    	newItemTextView.setBackgroundColor(getResources().getColor(R.color.light));
    	turn++;
    	}else{
    	newItemTextView.setBackgroundColor(getResources().getColor(R.color.dark));
    	turn--;
    	}
    	
    }
	
	public boolean onLongClick(View v) {
		
		TextView tv = (TextView) v;
		String message = tv.getText().toString();
		
		Intent smsIntent = new Intent(Intent.ACTION_VIEW);
		
		smsIntent.putExtra("sms_body", "To-Do List Item: " + message);
		smsIntent.putExtra("address", "");
		smsIntent.setType("vnd.android-dir/mms-sms");
		
		startActivity(smsIntent);
		
		return false;
		
	}
	

}
